package com.ly.test.config;

import org.mybatis.generator.api.MyBatisGenerator;
import org.mybatis.generator.config.Configuration;
import org.mybatis.generator.config.xml.ConfigurationParser;
import org.mybatis.generator.internal.DefaultShellCallback;

import java.net.URL;
import java.nio.file.Paths;
import java.util.ArrayList;
import java.util.List;
import java.util.Objects;

public class MBGRunner {
    public static void main(String[] args) throws Exception {
        List<String> warnings = new ArrayList<>();
        ConfigurationParser cp = new ConfigurationParser(warnings);

        URL url = MBGRunner.class.getClassLoader().getResource("generatorConfig.xml");
        Configuration config = cp.parseConfiguration(Paths.get(
                Objects.requireNonNull(url, "generatorConfig.xml not found").toURI()).toFile());

        DefaultShellCallback callback = new DefaultShellCallback(true);
        MyBatisGenerator generator = new MyBatisGenerator(config, callback, warnings);
        generator.generate(null);

        warnings.forEach(System.out::println);
        System.out.println("MBG done.");
    }
}
